package com.project.homework4_9.dao.impl;

import com.project.homework4_9.bean.LogForm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class BaseDao {
    private Connection con;
    private PreparedStatement ps;

    public static Connection getCon() {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection con= DriverManager.getConnection("jdbc:mysql://localhost:12345/me?characterEncoding=utf-8",
                    "root","lovo");
            return con;
        } catch (Exception e) {
            e.printStackTrace();
        }
    return null;
    }

    public void update(String content){
        LogForm logForm=new LogForm(content);
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con= DriverManager.getConnection("jdbc:mysql://localhost:12345/me?characterEncoding=utf-8",
                    "root","lovo");
            ps=con.prepareStatement("insert into t_log(l_content,l_time,l_date)values(?,?,?)");
            ps.setObject(1,logForm.getContent());
            ps.setObject(2,logForm.getTime());
            ps.setObject(3,logForm.getDate());
            ps.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        BaseDao dao= new BaseDao();
        dao.update("什么玩意");
    }
}
